package com.lrs.java.j2se_base.io;

import java.io.ByteArrayInputStream;

import com.lrs.java.j2se_advanced.codec.Hex;

public class DTCencodor {

	public static void main(String[] args) throws Exception {
		
		char[] c = {'P','C', 'B', 'U'};
		
		byte[] b = new byte[] {0x59, 0x02, (byte)0xD5, 0x62, 0x17, 0x2F};
		
		ByteArrayInputStream inputStream = new ByteArrayInputStream(b);
		
		
		byte[] first = new byte[2];
		byte[] s = new byte[3];
		
		inputStream.read(first);
		for(int i=0; i<first.length; i++) {
//			System.out.println(Integer.toBinaryString(first[i]));
		}

		StringBuilder str = new StringBuilder();
		int n;
		while((n=inputStream.read(s)) != -1) {
			
			for(int i=0; i<s.length; i++) {
				str.append(Integer.toBinaryString(s[i]) + "   ");
			}
			
			byte head = s[0];
			
			char prefix = c[(0xFF & head) >> 6];
			int middle = (byte)((0xFF & head) << 2) >> 6;
			int end = (0x0F & head);
			String hexStr = Hex.encodeHexStr(new byte[]{s[1]});
			
			str.append(prefix).append(middle).append(end).append(hexStr);
			
			int status = inputStream.read();
//			str.append(Integer.toBinaryString(status) + "   ");
		}
		System.out.println(str.toString());
		
		inputStream.close();
		
	}
}
